import Vue from 'vue'
import VueRouter from 'vue-router'
// import HelloWorld from '@/components/HelloWorld'

// Layout 和 SideBar 直接加载， 剩余部分懒加载
// 引入 Layout
import Layout_1 from 'components/Layout/Layout_1'
import Layout_2 from 'components/Layout/Layout_2'

import AuditCenter_side from 'components/SideBar/auditCenter_side'
import UserCenter_side from 'components/SideBar/usercenter_side'
import OrderCenter_side from 'components/SideBar/ordercenter_side'
import TradingCenter_side from 'components/SideBar/tradingcenter_side'
import SystemConfig_side from 'components/SideBar/systemconfig_side'

// 首页模块
const Home = resolve => require(['views/home/index'], resolve)

const EnterpriseAudit = resolve => require(['views/auditCenter/enterpriseAudit'], resolve)
const WorkReview = resolve => require(['views/auditCenter/workReview'], resolve)
//个人详情
const PersonlUser = resolve => require(['views/usercenter/personaluser'], resolve)
//个人用户

const AgentUserDetails = resolve => require(['views/usercenter/agentuserdetails'], resolve)
const PersonalDetails = resolve => require(['views/usercenter/personaldetails'], resolve)
const EnterPriseUsers = resolve => require(['views/usercenter/enterpriseusers'], resolve)
const EnterPriseUsersDetails = resolve => require(['views/usercenter/enterpriseusersdetails'], resolve)

const AgentUser = resolve => require(['views/usercenter/agentuser'], resolve)

const ZeroWorkList = resolve => require(['views/ordercenter/zeroworklist'], resolve)
const OrderList = resolve => require(['views/ordercenter/orderlist'], resolve)

const RechargeRecord = resolve => require(['views/tradingcenter/rechargerecord'], resolve)
const PresentRecord = resolve => require(['views/tradingcenter/presentrecord'], resolve)

const PlatformServiceCharge = resolve => require(['views/tradingcenter/platformservicecharge'], resolve)
const InvoiceTax = resolve => require(['views/tradingcenter/invoicetax'], resolve)
const InsuranceCost = resolve => require(['views/tradingcenter/insurancecost'], resolve)
const OrangeBalance = resolve => require(['views/tradingcenter/orangebalance'], resolve)
const OrangeDetail = resolve => require(['views/tradingcenter/orangedetail'], resolve)


const UserManagement = resolve => require(['views/systemconfig/usermanagement'], resolve)
const IPWhitelist = resolve => require(['views/systemconfig/IPwhitelist'], resolve)
const BuiltinaCount = resolve => require(['views/systemconfig/Builtinaccount'], resolve)

const routers = [
  {
    path: '/',
    component: Layout_2,
    children: [
      {path: '',redirect: 'dashboard'},
      { path: 'dashboard', component: Home, meta: { needAuth: false } }
    ]
  },
  {
    path: '/auditCenter',
    component: Layout_1,
    children: [
      { path: '', redirect: 'enterpriseAudit' },
      { path: 'enterpriseAudit', components: { dashboard: EnterpriseAudit , sidebar: AuditCenter_side }, meta: { needAuth: false } },
      { path: 'workreview', components: { dashboard: WorkReview, sidebar: AuditCenter_side }, meta: { needAuth: false } }
    ]
  },
  {
    path: '/usercenter',
    component: Layout_1,
    children: [
      { path: '', redirect: 'personaluser' },
      { path: 'personaluser/personaldetails', name: 'personaldetails', components: { dashboard: PersonalDetails, sidebar: UserCenter_side }, meta: { needAuth: false } },
      { path: 'agentuser/agentuserdetails', name: 'agentuserdetails', components: { dashboard: AgentUserDetails, sidebar: UserCenter_side }, meta: { needAuth: false } },

      { path: 'personaluser/enterpriseusersdetails', name: 'enterpriseusersdetails', components: { dashboard: EnterPriseUsersDetails, sidebar: UserCenter_side }, meta: { needAuth: false } },
      { path: 'enterpriseusers', name: 'enterpriseusers', components: { dashboard: EnterPriseUsers, sidebar: UserCenter_side }, meta: { needAuth: false, keepAlive: true } },
      { path: 'agentuser', name: 'agentuser',components: { dashboard: AgentUser, sidebar: UserCenter_side }, meta: { needAuth: false } },
      { path: 'personaluser', name: 'personaluser', title: 'personaluser',components: { dashboard: PersonlUser, sidebar: UserCenter_side }, meta: { pageTitle: "personaluser", keepAlive:true } }
    ]
  },
  {
    path: '/ordercenter',
    component: Layout_1,
    children: [
      { path: '', redirect: 'zeroworklist' },
      { path: 'zeroworklist', components: { dashboard: ZeroWorkList, sidebar: OrderCenter_side }, meta: { needAuth: false } },
      { path: 'orderlist', components: { dashboard: OrderList, sidebar: OrderCenter_side }, meta: { needAuth: false } },

    ]
  },
  {
    path: '/tradingcenter',
    component: Layout_1,
    children: [
      { path: '', redirect: 'rechargerecord' },
      { path: 'rechargerecord', components: { dashboard: RechargeRecord, sidebar: TradingCenter_side }, meta: { needAuth: false } },
      { path: 'presentrecord', components: { dashboard: PresentRecord, sidebar: TradingCenter_side }, meta: { needAuth: false } },
      { path: 'platformservicecharge', components: { dashboard: PlatformServiceCharge, sidebar: TradingCenter_side }, meta: { needAuth: false } },
      { path: 'invoicetax', components: { dashboard: InvoiceTax, sidebar: TradingCenter_side }, meta: { needAuth: false } },
      { path: 'insurancecost', components: { dashboard: InsuranceCost, sidebar: TradingCenter_side }, meta: { needAuth: false } },
      { path: 'orangebalance', components: { dashboard: OrangeBalance, sidebar: TradingCenter_side }, meta: { needAuth: false } },
      { path: 'orangedetail', components: { dashboard: OrangeDetail, sidebar: TradingCenter_side }, meta: { needAuth: false } },
    ]
  },
  {
    path: '/systemconfig',
    component: Layout_1,
    children: [
      { path: '', redirect: 'usermanagement' },
      { path: 'usermanagement', components: { dashboard: UserManagement, sidebar: SystemConfig_side }, meta: { needAuth: false } },
      { path: 'IPwhitelist', components: { dashboard: IPWhitelist, sidebar: SystemConfig_side }, meta: { needAuth: false } },
      { path: 'Builtinaccount', components: { dashboard: BuiltinaCount, sidebar: SystemConfig_side }, meta: { needAuth: false } },
    ]
  },
]

const router = new VueRouter({
  mode: 'hash',
  routes: routers
})

// router.afterEach((to, from) => {
//   if (from.name == 'personaluser' && to.name == 'personaldetails'){
//     let h = sessionStorage.getItem('isd')
//     if(h == '0'){
//       window.sessionStorage.setItem("isd",null);
//       window.location.reload();
//     }else {
//       window.sessionStorage.setItem("isd",0)
//     }
//   } else if (from.name != 'personaldetails' && to.name =='personaluser'){
//     window.sessionStorage.setItem('isd',0)
//   }
// })

export default router

